import 'dart:convert';

import 'package:flutter_app/bean/file_path_entity.dart';

ChunkFile chunkFileFromJson(String str) => ChunkFile.fromJson(json.decode(str));

String chunkFileToJson(ChunkFile data) => json.encode(data.toJson());

// 获取文件上传和分片信息
class ChunkFile {
  ChunkFile({
    this.chunkTotal,
    this.fileMd5,
    this.fileName,
    this.fileShowVO,
    this.fileSize,
    this.id,
    this.itemList,
    this.status,
  });

  ChunkFile.fromJson(dynamic json) {
    chunkTotal = json['chunkTotal'];
    fileMd5 = json['fileMd5'];
    fileName = json['fileName'];
    fileShowVO = json['fileShowVO'] != null
        ? FilePathEntity.fromJson(json['fileShowVO'])
        : null;
    fileSize = json['fileSize'];
    id = json['id'];
    if (json['itemList'] != null) {
      itemList = [];
      json['itemList'].forEach((v) {
        itemList?.add(ItemList.fromJson(v));
      });
    }
    status = json['status'];
  }

  num? chunkTotal;
  String? fileMd5;
  String? fileName;
  FilePathEntity? fileShowVO;
  num? fileSize;
  String? id;
  List<ItemList>? itemList;
  String? status;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['chunkTotal'] = chunkTotal;
    map['fileMd5'] = fileMd5;
    map['fileName'] = fileName;
    if (fileShowVO != null) {
      map['fileShowVO'] = fileShowVO?.toJson();
    }
    map['fileSize'] = fileSize;
    map['id'] = id;
    if (itemList != null) {
      map['itemList'] = itemList?.map((v) => v.toJson()).toList();
    }
    map['status'] = status;
    return map;
  }
}

ItemList itemListFromJson(String str) => ItemList.fromJson(json.decode(str));

String itemListToJson(ItemList data) => json.encode(data.toJson());

class ItemList {
  ItemList({
    this.chunkIndex, // 片坐标
    this.chunkSize, // 片大小
    this.id, //
    this.status,
  });

  ItemList.fromJson(dynamic json) {
    chunkIndex = json['chunkIndex'];
    chunkSize = json['chunkSize'];
    id = json['id'];
    status = json['status'];
  }

  num? chunkIndex;
  num? chunkSize;
  String? id;
  String? status;

  Map<String, dynamic> toJson() {
    final map = <String, dynamic>{};
    map['chunkIndex'] = chunkIndex;
    map['chunkSize'] = chunkSize;
    map['id'] = id;
    map['status'] = status;
    return map;
  }
}